package ru.vpitervip.server.domain;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Version;
import javax.swing.text.DateFormatter;

import org.springframework.beans.factory.annotation.Configurable;


@Entity
@Table(name="application")
@Configurable
public class Application {

final public static int ZERO_STATUS=0;	
final public static int INWORK_STATUS=1;		
final public static int WORKED_STATUS=2;		
final public static int PREPAID_STATUS=3;
final public static int HOSTED_STATUS=4;
final public static int CANCEL_STATUS=5;	
	

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
private Integer id;

@Version
@Column(name = "version")
private Integer version;

@Column
private int status;

@Column
private String name;

@Column
private String tel;

@Column
private String email;

@Column
private int objectId;

@Column
private Date inDate;

@Column
private Date outDate;

@Column
private double dayNum;

@Column
private int peopleNum;

@Column
private int commision;

@Column
private int prepay;

@Column
private String note;

@Column
private Date addDate;


private String payMethod;



public Application() {
	
	
	peopleNum=2;
	payMethod="";
	addDate=new Date();
	
}



public void commit(){
	
//	System.out.println("Starting commit");
	
	   Date now=new Date();
	   
	   DateFormat dateFormat = new SimpleDateFormat("dd.MM.yyyy HH:mm");
	
       MailMessage mailMessage=new MailMessage();
       
//       System.out.println("Created mailMessage");
       
       mailMessage.setAddress("contact@vpiter-vip.ru");
       mailMessage.setDate(new Date());
       mailMessage.setFrom(email);
       mailMessage.setTopic("vpiter-vip:бронирование");

//       System.out.println("Constracting message");
       
       String message=" ID номер: "+objectId+"\n"+
    		   "отправлена: "+dateFormat.format(now)+"\n"+
    		   "Имя: "+name+"\n"+
    		   "e-mail: "+email+"\n"+
    		   "Телефон: "+tel+"\n"+
    		   "Дата прибытия: "+(inDate==null?"":dateFormat.format(inDate))+"\n"+
    		   "Дата выезда: "+(outDate==null?"":dateFormat.format(outDate))+"\n"+
    		   "Количество человек: "+peopleNum+"\n"+
    		   "Сообщение: "+note;
       
//       System.out.println("Message constracted");
       
       mailMessage.setFromInfo(name);
       
       mailMessage.setMessage(message);
       
//       System.out.println("Ready to send message");
	
	   mailMessage.send();
	
}




public Integer getId() {
	return id;
}

public void setId(Integer id) {
	this.id = id;
}

public String getName() {
	return name;
}

public void setName(String name) {
	this.name = name;
}



public String getTel() {
	return tel;
}

public void setTel(String tel) {
	this.tel = tel;
}

public String getEmail() {
	return email;
}

public void setEmail(String email) {
	this.email = email;
}


public int getObjectId() {
	return objectId;
}

public void setObjectId(int objectId) {
	this.objectId = objectId;
}

public Date getInDate() {
	return inDate;
}

public void setInDate(Date inDate) {
	this.inDate = inDate;
}

public Date getOutDate() {
	return outDate;
}

public void setOutDate(Date outDate) {
	this.outDate = outDate;
}

public int getPeopleNum() {
	return peopleNum;
}

public void setPeopleNum(int peopleNum) {
	this.peopleNum = peopleNum;
}


public Date getAddDate() {
	return addDate;
}

public void setAddDate(Date addDate) {
	this.addDate = addDate;
}

public int getStatus() {
	return status;
}

public void setStatus(int status) {
	this.status = status;
}

public double getDayNum() {
	return dayNum;
}

public void setDayNum(double dayNum) {
	this.dayNum = dayNum;
}

public int getCommision() {
	return commision;
}

public void setCommision(int commision) {
	this.commision = commision;
}

public int getPrepay() {
	return prepay;
}

public void setPrepay(int prepay) {
	this.prepay = prepay;
}

public String getNote() {
	return note;
}

public void setNote(String note) {
	this.note = note;
}



public String getPayMethod() {
	return payMethod;
}

public void setPayMethod(String payMethod) {
	this.payMethod = payMethod;
}

public Integer getVersion() {
	return version;
}

public void setVersion(Integer version) {
	this.version = version;
}


}
